package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.BizAssessToDept;
import com.aidex.biz.service.BizAssessToDeptService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 考核部门Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-11-29
 */
@RestController
@RequestMapping("/biz/bizAssessToDept")
public class BizAssessToDeptController extends BaseController
{
    @Autowired
    private BizAssessToDeptService bizAssessToDeptService;

    /**
     * 查询考核部门列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizAssessToDept bizAssessToDept, HttpServletRequest request, HttpServletResponse response)
    {

        bizAssessToDept.setPage(new PageDomain(request, response));
//        bizAssessToDept.setDeptId(SecurityUtils.getDeptId());
//        bizAssessToDept.setAssessDept(SecurityUtils.getDeptId());
        return R.data(bizAssessToDeptService.findPage(bizAssessToDept));
    }

    /**
     * 查询考核部门列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:list')")
    @GetMapping("/listPingFen")
    public R<PageInfo> listPingFen(BizAssessToDept bizAssessToDept, HttpServletRequest request,
            HttpServletResponse response)
    {

        bizAssessToDept.setPage(new PageDomain(request, response));

        return R.data(bizAssessToDeptService.findPage(bizAssessToDept));
    }

    /**
     * 查询考核部门列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:list')")
    @GetMapping("/assessDetplist")
    public R<PageInfo> assessDetplist(BizAssessToDept bizAssessToDept, HttpServletRequest request,
            HttpServletResponse response)
    {

        bizAssessToDept.setPage(new PageDomain(request, response));
        return R.data(bizAssessToDeptService.findPage(bizAssessToDept));
    }

    /**
     * 获取考核部门详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:query')")
    @GetMapping(value = "/{id}")
    public R<BizAssessToDept> detail(@PathVariable("id") String id)
    {
        return R.data(bizAssessToDeptService.get(id));
    }

    /**
     * 新增考核部门
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:add')")
    @Log(title = "考核部门", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizAssessToDept bizAssessToDept)
    {
        return R.status(bizAssessToDeptService.save(bizAssessToDept));
    }

    /**
     * 修改考核部门
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:edit')")
    @Log(title = "考核部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizAssessToDept bizAssessToDept)
    {
        return R.status(bizAssessToDeptService.save(bizAssessToDept));
    }


    /**
     * 删除考核部门
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:remove')")
    @Log(title = "考核部门", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(bizAssessToDeptService.deleteBizAssessToDeptByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(bizAssessToDeptService.findMaxSort(new BizAssessToDept()));
    }

    /**
     * 导出考核部门列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessToDept:export')")
    @Log(title = "考核部门", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizAssessToDept bizAssessToDept)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    bizAssessToDept.setCompanyId(null);
            }else{
                         bizAssessToDept.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<BizAssessToDept> list = bizAssessToDeptService.findList(bizAssessToDept);
        ExcelUtil<BizAssessToDept> util = new ExcelUtil<BizAssessToDept>(BizAssessToDept.class);
        return util.exportExcel(list, "考核部门数据");
    }

}
